# Instead of computing divisor of each number
# We compute sum of divisor with sieving technique
#
# for divisor in 1:limit
#   For k = 2:limit
#   D[k * divisor] += divisor

def Solve():
    limit = 10000

    # Generate all D(n)
    D = [0] * limit
    for divisor in xrange(1, limit):
        for n in xrange(2*divisor, limit, divisor):
            D[n] += divisor

    # Check amicable number
    result = 0
    for n in xrange(1, limit):
        if D[n] < n:
            if D[D[n]] == n:
                result += n + D[n]

    return result
